home *** CD-ROM | disk | FTP | other *** search
- /*
- Defs.h
-
- Type definitions for Graphic Elements release version 1.0b1
-
- Updated 1/9/95 for Graphic Elements version 3.0
-
- Copyright 1994 by Al Evans. All rights reserved.
-
-
- */
-
- #ifndef GEDEFS
- #define GEDEFS
-
- #include "Preload.h"
- #include "List.h"
-
- //All offscreen graphics are 8 bits deep
- #define offscrnDepth 8
-
- //Some forward declarations
- typedef struct GrafElement* GrafElPtr;
- typedef struct GEWorld* GEWorldPtr;
-
- //Built-in directions
- typedef enum {none, up, left, down, right, upLeft, upRight, downLeft, downRight} GEDirection;
-
- //Constant for "same-size" worlds
- #define scaleOneToOne 0x00010000
-
- /*
- Prototype of function to initialize a graphic element from a resource or series
- of resources. This function is responsible for creating an offscreen GWorld
- for the element if required, and rendering the resource(s) into it.
-
- This function is responsible for setting the fields element->resID, element->graphRect,
- and element->graphWorld.
- */
-
- GE_CALLBACK_TDEF(Boolean,GraphicLoadFunc) (GEWorldPtr world, GrafElPtr element,
- short startResNum, short nResources);
-
- /*
- Prototype of function which, if present, will be called every time world is
- updated, after drawing is complete. Can be used to automate other services
- which need frequent time slices, such as sound maintenance procedures.
- */
-
- GE_CALLBACK_TDEF(void, FramePostProcFunc) (GEWorldPtr world, Ptr data);
-
- /*
- Prototype for general-purpose bit copy function type-compatible
- with CopyBits. BitCopyProcs are normally used for
- offscreen-to-offscreen copying only. NOTE THAT THE PARAMETER
- maskRgn IS ALMOST NEVER A MASK REGION! It is passed from the
- drawData field of the graphic record. It should normally be nil,
- but can be used for data required by a specific custom bitcopying
- procedure.
-
- If the "real" CopyBits is used directly for offscreen-to-offscreen
- drawing, care must be taken that this field is nil or contains a
- real region handle.
- */
-
- GE_CALLBACK_TDEF(void,BitCopyProc) (const BitMap *srcBits, const BitMap *dstBits,
- const Rect *srcRect, const Rect *dstRect,
- short mode, RgnHandle maskRgn);
-
- /*
- Prototype for autochange procedure, which periodically moves graphic,
- changes frames, scrolls graphic, etc.
- */
-
- GE_CALLBACK_TDEF(void,AutoChangeProc) (GEWorldPtr world, GrafElPtr element);
-
- /*
- Prototype for interact procedure, which handles collisions
- */
-
- typedef enum {collisionBegin, collisionContinue, collisionEnd} CollisionPhase;
-
- GE_CALLBACK_TDEF(void,CollisionProc)(GEWorldPtr world, GrafElPtr element,
- GEDirection dir, CollisionPhase phase,
- GrafElPtr hitElement);
-
- /*
- Prototype for rendering procedure to draw element
- into offscreen "stage" world
- */
-
- GE_CALLBACK_TDEF(void,RenderProc)(GrafElPtr element, GWorldPtr destGWorld);
-
- /*
- Prototype for sensor-tracking procedure, called when mouse
- button is pressed in a graphic element with sensor properties
- */
-
- GE_CALLBACK_TDEF(Boolean,SensorTrack)(GEWorldPtr world, GrafElPtr sensor);
-
- /*
- Prototype for action procedure to be called by sensor
- */
-
- GE_CALLBACK_TDEF(void,SensorAction)(GEWorldPtr world, GrafElPtr sensor, short sensorState);
-
- /*
- Prototype for "custom" dispose procedure, called when Graphic Element is
- disposed to give element a chance to free up any memory it has allocated.
- */
-
- GE_CALLBACK_TDEF(void,CleanupProc)(GEWorldPtr world, GrafElPtr element);
-
- /*
- Defined values for flags field of Graphic Element. Bits 5-13 are reserved
- for future system use, bits 16-31 are available for use in defining
- custom Graphic Elements.
- */
-
- enum { geShown = 0x00000001L,
- geChanged = 0x00000002L,
- geHit = 0x00000004L,
- geSensor = 0x00000008L,
- geForward = 0x00000010L,
- geMirrored = 0x00004000L,
- geInverted = (short)0x8000
- };
-
- /*
- The structure of an entry in a world's sensorList
- */
-
- typedef struct SensorListEntry *SListEntryPtr;
-
- typedef struct SensorListEntry {
- SListEntryPtr nextEntry;
- Rect sensorRect;
- OSType sensorID;
- } SensorListEntry;
-
- /*
- Forward declaration of a GE Timer record (see GETimer.h)
- */
-
- typedef struct GETMgrRec *GETMgrRecPtr;
-
- /*
- A basic Graphic Element
- */
-
- typedef struct GrafElement{
-
- //Bookkeeping and access
- GrafElPtr nextByPlane; //Link in world's drawList
- GrafElPtr nextByID; //Link in world's idList
- GrafElPtr masterGrafEl; //Master (if any) controls movement of this GrafEl
- GrafElPtr slaveGrafEl; //This GrafEl controls movement of slave (if any)
- OSType objectID; //This element's "name"
- short drawPlane; //"Level" of object, higher number == closer to front
- short resID; //# of resource from which element was derived, if any
- long flags; //See definitions above
- CleanupProc cleanupProc; //Custom dispose procedure, if any
-
- //Basic graphics data
- GWorldPtr graphWorld; //Ptr to offscreen graphic, if any
- Rect graphRect; //Source rectangle used by RenderProc
- Rect animationRect; //Total dest rectangle, GEWorld coordinates
- RenderProc renderIt; //Element's rendering procedure
- BitCopyProc drawIt; //Lowlevel bit copier, if any
- Ptr drawData; //Data passed to drawIt, if any
- Rect drawRect; //Rect to update on this cycle
- short copyMode; //Bit transfer mode
-
- //For automatic periodic changes
- short changeIntrvl; //Interval between automatic changes
- unsigned long lastChangeTime; //Last time autochange proc was called
- AutoChangeProc changeIt; //Function for automatic changes
- Ptr changeData; //Extra data for automatic changes
-
- //For collisions
- CollisionProc doCollision; //Proc called when element collides
- short collisionPlane; //Collides only with elements on this plane
- GrafElPtr collideElement; //Other element involved in this collision
-
- //For direct user interactions
- short sensorType; //Used to distinguish variant types
- SensorTrack trackingProc; //Called when mousedown in sensor's rectangle
- SensorAction actionProc; //Called by trackingProc when sensor is "activated"
- short sensorState; //For whatever a sensor needs to save across calls
- } GrafElement;
-
- /*
- A world of Graphic Elements
- */
-
- typedef struct GEWorld {
-
- GEWorldPtr nextWorld;
-
- //Objects maintained by this world
- GrafElPtr drawList; //Head of linked list of GrafElements in draw order
- GrafElPtr idList; //Head of linked list of GrafElements by ID
-
- //Graphic environment of this world
- GrafPtr gEWPort; //Onscreen GrafPort for this world
- GDHandle portGDevice; //Device for this port
- GWorldPtr stageGWorld; //Offscreen construction "stage" for this world
- Rect animationRect; //Total dest rect of this world
- CTabHandle worldCTable; //Offscreen color table, should == onscreen cTable
- Point worldFocus; //Offset of world from window top left
- Fixed worldScale; //Ratio of screen pixels to world pixels
-
- //Current state of this world
- GraphicLoadFunc defaultLoader; //Loader used if no other is specified
- FramePostProcFunc postProcFunc; //Called after every update
- Ptr userData; //Extra world data (passed to postProcFunc)
- LHeaderPtr activeRectList; //Two lists of update rects, so that animation and
- LHeaderPtr safeRectList; //screen updating can be concurrent
- LHeaderPtr sensorList; //Sensors in this world, see Sensors.h
- RgnHandle clipRgn; //Total clip region for this world
- RgnHandle otherWorldsCover; //in grafport coordinates
- RgnHandle userCovered; //in grafport coordinates
- GETMgrRecPtr worldTime; //Timer record for this world
- unsigned long lastFrameTime; //last time screen was updated
- short msPerFrame; //minimum "projection" interval, ms
- Boolean active; //True if this animation is running
- Boolean changed; //True if at least 1 object needs drawing
- Boolean onTop; //True if topmost world
- } GEWorld;
-
- #endif
-